package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.vo.AnalysisVo;
import com.ruoyi.system.vo.TranslateVo;
import com.ruoyi.system.vo.ZipFileVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BusinessAnalysis;
import com.ruoyi.system.service.IBusinessAnalysisService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件解析Controller
 * 
 * @author ruoyi
 * @date 2024-09-18
 */
@Controller
@RequestMapping("/system/analysis")
@Api("文件解析")
public class BusinessAnalysisController extends BaseController
{
    private String prefix = "system/analysis";

    @Autowired
    private IBusinessAnalysisService businessAnalysisService;

    @RequiresPermissions("system:analysis:view")
    @GetMapping()
    public String analysis()
    {
        return prefix + "/analysis";
    }

    /**
     * 查询文件解析列表
     */
    @RequiresPermissions("system:analysis:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TranslateVo vo)
    {
        startPage();
        List<BusinessAnalysis> list = businessAnalysisService.selectBusinessAnalysisList(vo);
        return getDataTable(list);
    }

    /**
     * 导出文件解析列表
     */
    @RequiresPermissions("system:analysis:export")
    @Log(title = "文件解析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TranslateVo vo)
    {
        List<BusinessAnalysis> list = businessAnalysisService.selectBusinessAnalysisList(vo);
        ExcelUtil<BusinessAnalysis> util = new ExcelUtil<BusinessAnalysis>(BusinessAnalysis.class);
        return util.exportExcel(list, "文件解析数据");
    }

    /**
     * 新增文件解析
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存文件解析
     */
    @RequiresPermissions("system:analysis:add")
    @Log(title = "文件解析", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusinessAnalysis businessAnalysis)
    {
        return toAjax(businessAnalysisService.insertBusinessAnalysis(businessAnalysis));
    }


    /**
     * 文件压缩
     * @param zipFileVo
     * @return
     * @throws Exception
     */

    @ApiOperation("文件压缩")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fileType", value = "文件类型 1、图片 2、视频 3、遍历指定图片文件文件夹下所有图片, 4、遍历指定图片文件文件夹下所有视频", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "sourceFilePath", value = "源文件夹路径", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "targetFilePath", value = "目标文件夹路径", dataType = "String", dataTypeClass = String.class),
    })
    @PostMapping("/zipfile")
    @ResponseBody
    public AjaxResult zipFile(@Validated ZipFileVo zipFileVo) throws Exception {
        return businessAnalysisService.zipFile(zipFileVo);
    }
    @ApiOperation("删除文件夹下文件")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "type", value = "文件类型 1、图片 2、视频 3、文档", dataType = "Integer", dataTypeClass = Integer.class),
    @ApiImplicitParam(name = "path", value = "文件夹路径", dataType = "String", dataTypeClass = String.class),
    })
    @PostMapping("/delFile")
    @ResponseBody
    public AjaxResult delFile(String path,Integer type) throws Exception {
        return businessAnalysisService.delFile(path,type);
    }


    @ApiOperation("文件解析")
    @PostMapping("/analysis")
    @ResponseBody
    public AjaxResult analysis( @RequestBody AnalysisVo analysisVo) throws Exception {
        return businessAnalysisService.analysis(analysisVo);
    }

    @ApiOperation("拍照大师文件解析")
    @PostMapping("/photoAnalysis")
    @ResponseBody
    public AjaxResult photoanalysis( @RequestBody AnalysisVo analysisVo) throws Exception {
        return businessAnalysisService.photoAnalysis(analysisVo);
    }

    @ApiOperation("文件翻译")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "analysisCatagory", value = "解析类型  1 线上图片解析 2 本地上传图片解析  3 线上视频解析 4 本地上传视频解析", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "analysis", value = "解析描述", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "fileCatagory", value = "业务类型", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "endTime", value = "开始时间", dataType = "String", dataTypeClass = String.class),
    })
    @PostMapping("/translate")
    @ResponseBody
    public AjaxResult translate(@Validated TranslateVo translateVo) throws Exception {
        return businessAnalysisService.translate(translateVo);
    }

    @ApiOperation("文件导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "analysisCatagory", value = "解析类型  1 线上图片解析 2 本地上传图片解析  3 线上视频解析 4 本地上传视频解析", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "analysis", value = "解析描述", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "fileCatagory", value = "业务类型", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "endTime", value = "开始时间", dataType = "String", dataTypeClass = String.class),
    })
    @PostMapping("/fileOutPut")
    @ResponseBody
    public AjaxResult fileOutPut(@Validated TranslateVo translateVo) throws Exception {
        return businessAnalysisService.fileOutPut(translateVo);
    }
    @ApiOperation("拍照大师文件导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "analysisCatagory", value = "解析类型  1 线上图片解析 2 本地上传图片解析  3 线上视频解析 4 本地上传视频解析", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "analysis", value = "解析描述", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "fileCatagory", value = "业务类型", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "endTime", value = "开始时间", dataType = "String", dataTypeClass = String.class),
    })
    @PostMapping("/photoFileOutPut")
    @ResponseBody
    public AjaxResult photoFileOutPut(@Validated TranslateVo translateVo) throws Exception {
        return businessAnalysisService.photoFileOutPut(translateVo);
    }

    @ApiOperation("文件夹导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "analysisCatagory", value = "解析类型  1 线上图片解析 2 本地上传图片解析  3 线上视频解析 4 本地上传视频解析", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "analysis", value = "解析描述", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "fileCatagory", value = "业务类型", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "endTime", value = "开始时间", dataType = "String", dataTypeClass = String.class),
    })
    @PostMapping("/folderOutPut")
    @ResponseBody
    public AjaxResult folderOutPut(@Validated TranslateVo translateVo) throws Exception {
        return businessAnalysisService.folderOutPut(translateVo);
    }



    @ApiOperation("文件优化")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "path", value = "文件夹路径", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "fileCatagory", value = "业务类型", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult fileOptimization(String path,String fileCatagory) throws Exception {
        return businessAnalysisService.fileOptimization(path,fileCatagory);
    }
    /**
     * 修改文件解析
     */
    @RequiresPermissions("system:analysis:edit")
    @GetMapping("/edit/{analysisId}")
    public String edit(@PathVariable("analysisId") Long analysisId, ModelMap mmap)
    {
        BusinessAnalysis businessAnalysis = businessAnalysisService.selectBusinessAnalysisByAnalysisId(analysisId);
        mmap.put("businessAnalysis", businessAnalysis);
        return prefix + "/edit";
    }

    /**
     * 修改保存文件解析
     */
    @RequiresPermissions("system:analysis:edit")
    @Log(title = "文件解析", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusinessAnalysis businessAnalysis)
    {
        return toAjax(businessAnalysisService.updateBusinessAnalysis(businessAnalysis));
    }

    /**
     * 删除文件解析
     */
    @RequiresPermissions("system:analysis:remove")
    @Log(title = "文件解析", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(businessAnalysisService.deleteBusinessAnalysisByAnalysisIds(ids));
    }
}
